<template>
  <div class="app-container customer-div">
      <!--搜索-->
      <el-form :inline="true" :model="listQuery" size="mini" label-width="100px">
        <el-form-item label="客户名称：">
          <el-input v-model="listQuery.customerName"></el-input>
<!--          <el-autocomplete-->
<!--            clearable-->
<!--            class="inline-input"-->
<!--            value-key="customerName"-->
<!--            :fetch-suggestions="querySearch"-->
<!--            v-model="listQuery.customerName"-->
<!--            placeholder="请输入内容"-->
<!--            @select="handleSelectCustomerName"-->
<!--            :trigger-on-focus="false"-->
<!--          ></el-autocomplete>-->
        </el-form-item>
<!--        <el-form-item label="日期：">-->
<!--          <el-date-picker-->
<!--            v-model="listQuery.deliverDate"-->
<!--            type="daterange"-->
<!--            format="yyyy 年 MM 月 dd 日"-->
<!--            value-format="yyyy-MM-dd"-->
<!--            range-separator="至"-->
<!--            start-placeholder="开始日期"-->
<!--            end-placeholder="结束日期">-->
<!--          </el-date-picker>-->
<!--        </el-form-item>-->
        <el-form-item label="业务员：" v-if="listQuery.type == 'all'">
          <el-select v-model="listQuery.userId" filterable placeholder="请选择" clearable>
            <el-option
              v-for="item in userOptionList"
              :key="item.userId"
              :label="item.userName"
              :value="item.userId">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button
            @click="handleSearchList()"
            type="primary">
            查询
          </el-button>


        </el-form-item>
      </el-form>

    <!--数据列表-->
    <div class="table-container">
      <div style="overflow: hidden;font-size:14px;color:#606266;">
<!--        <div style="float:left">-->
<!--          需跟进<span style="font-weight: bold;padding:0 5px">250</span>次，-->
<!--          已完成<span style="font-weight: bold;padding:0 5px">250</span>次，-->
<!--          需拜访<span style="font-weight: bold;padding:0 5px">250</span>次，-->
<!--          已完成<span style="font-weight: bold;padding:0 5px">250</span>次-->
<!--        </div>-->
        <div style="float:right">
            <div style="display: inline-block;vertical-align: middle;margin-right:10px">
               <span class="xgj"></span>
               <span style="display: inline-block;vertical-align: middle">需跟进</span>
            </div>
            <div style="display: inline-block;vertical-align: middle;margin-right:10px">
              <span class="ygj"></span>
              <span style="display: inline-block;vertical-align: middle">已跟进</span>
            </div>
            <div style="display: inline-block;vertical-align: middle;margin-right:10px">
              <span class="xbf"></span>
              <span style="display: inline-block;vertical-align: middle">需拜访</span>
            </div>
            <div style="display: inline-block;vertical-align: middle">
              <span class="ybf"></span>
              <span style="display: inline-block;vertical-align: middle">已拜访</span>
            </div>
        </div>
      </div>

      <el-table
        v-loading="listLoading"
        :data="tableData"
        border
        style="width: 100%; margin-top: 20px">
        <el-table-column  label="客户名称" width="200"  fixed="left" header-align="center">
          <template slot-scope="scope">
              <el-link @click="toDetail(scope.row)" type="primary">
                {{scope.row.customerName}}
              </el-link>
          </template>
        </el-table-column>

        <el-table-column
          fixed="left"
          label="产品线"
          align="center"
          width="150">
          <template slot-scope="scope">
              {{scope.row.goodsLineNames}}
          </template>
        </el-table-column>
        <el-table-column
          fixed="left"
          label="负责人"
          align="center"
          width="100">
          <template slot-scope="scope">
            {{scope.row.userName}}
          </template>
        </el-table-column>
        <el-table-column
          fixed="left"
          label="阶段 "
          width="100"
          align="center">
          <template slot-scope="scope">
            {{scope.row.stepName}}
          </template>
        </el-table-column>

        <el-table-column
          min-width="100"
          align="center" v-for="(n,i) in days" :key="dateStamp+60*60*24*i*1000">
          <template slot="header" slot-scope="scope">
               {{(dateStamp+60*60*24*i*1000) | formatCreateTime}}
          </template>
          <template slot-scope="scope">
            <span v-for="item in scope.row[(dateStamp+60*60*24*i*1000)/1000] ">
                 <span class="xgj" v-if="item == 1"></span>
                 <span class="ygj" v-if="item == 3"></span>
                 <span class="xbf" v-if="item==2"></span>
                 <span class="ybf" v-if="item==4"></span>
            </span>
          </template>
        </el-table-column>

        <el-table-column
          width="100"
          fixed="right"
          label="操作"
          align="center">
          <template slot-scope="scope">
            <el-button
              v-if="listQuery.type != 'all'"
              type="text"
              size="mini"
              @click="showGj(scope.row,'add')">新增跟进
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[10,15,20]"
        :total="count">
      </el-pagination>
    </div>
    <!--新增跟进-->
    <addGj ref="addGj" @getList="getList"></addGj>
  </div>
</template>
<script>
import addGj  from './addGj'
import {getCustomerOption,getOrderUsersList,getDeliverList,deliverUpdate,getQiniuToken,postDeliverVoucher,saleDeliversExportAll,deliverBill} from '@/api/partner'
import {formatDate} from '@/utils/date';
import {trackingPlanTracking} from '@/api/company'
import {validateCommission} from '@/utils/validate';
import store from '@/store'
import "@/utils/jQuery.print"
import { mapGetters } from 'vuex'
import trajectoryMap from '@/views/components/trajectoryMap'
const defaultListQuery={
  pageNum: 1,
  pageSize: 10,
  type:'',
  userId:null,
  customerName:''
};
const defaultSendForm={
  deliverId: '',
  goodsReceipt: [],
  goodsReceiptRemark: '',
  goodsReceiptDate:''
};
export default {
  name: "followCalendar",
  data(){
    return {
      listQuery: JSON.parse(JSON.stringify(defaultListQuery)),
      tableData: [],
      count: 0,
      listLoading: false,
      roles:store.getters.roles ? store.getters.roles : [],
      dateStamp:0,
      days:16,
      userOptionList:[]
    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  created() {

  },
  filters: {
    formatCreateTime(time) {
      if(time){
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd')
      }else{
        return '--'
      }
    },
  },
  components : {
    addGj

  },
  methods:{
    //新增跟进
    showGj(item,type){
      this.$refs.addGj.showTracking(item,type,this.listQuery.type)
    },
    //获取员工下拉选项
    getUserOptionListData(){
      getOrderUsersList().then((res)=>{
        this.userOptionList = res;
      })
    },
    init(type){
      this.dateStamp = new Date(new Date().toLocaleDateString()).getTime();
      this.listQuery.type = type
      this.getList();
      this.getUserOptionListData()
    },


    //去客户详情页
    toDetail(item){
      let routeData = this.$router.resolve({name:'customerDetail',query:{id:item.customerId}});
      window.open(routeData.href);
    },

    //客户名称输入匹配
    querySearch(queryString, cb){
      getCustomerOption({keywords:queryString}).then((res)=>{
        cb(res);
      })
    },


    //选择客户名称
    handleSelectCustomerName(item){
      this.listQuery.customerName = item.customerName
    },


    handleSizeChange(val){
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val){
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleSearchList(){
      this.listQuery.pageNum = 1;
      // if(this.listQuery.deliverDate&&this.listQuery.deliverDate.length > 0){
      //   this.dateStamp = new Date(new Date(this.listQuery.deliverDate[0]).toLocaleDateString()).getTime();
      //   let endTime = new Date(new Date(this.listQuery.deliverDate[1]).toLocaleDateString()).getTime();
      //   this.days = (endTime-this.dateStamp)/(60*60*24*1000) + 1
      // }else{
      //   this.days = 91;
      //   this.dateStamp = new Date(new Date().toLocaleDateString()).getTime();
      // }
      this.getList();
    },

    //获取列表
    getList() {
      this.listLoading = true;
      trackingPlanTracking(this.listQuery).then(response => {
        this.tableData = response.list;
        this.count = response.count;
        this.listLoading = false;
      }).catch(()=>{
        this.listLoading = false;
      });
    },






  },
}
</script>

<style>
  .xgj{
    display: inline-block;width:16px;height:16px;border-radius: 50%;background: rgb(255,102,0);vertical-align: middle
  }
  .ygj{
    display: inline-block;width:16px;height:16px;border-radius: 50%;background: rgb(0,128,0);vertical-align: middle
  }
  .xbf{
    display: inline-block;width:16px;height:16px;border-radius: 50%;border:2px solid  rgb(255,102,0);vertical-align: middle
  }
  .ybf{
    display: inline-block;width:16px;height:16px;border-radius: 50%;border:2px solid rgb(0,128,0);vertical-align: middle
  }
</style>



